<include file="./Application/Home/View/Public/Base/_meta.html"/>
<block name="body">
    <style>
        .mk-hasbtn{
            margin-top: 0px;
        }

        .table th,.table td{
            font-size: 13px;
        }

        .table th{
            background: #E0EAF6 !important;
        }

        .mk-row{
            margin-bottom: 20px;
            padding: 0px 4%;
        }

        .mk-row label{
            display: block;
            margin-bottom: 10px;
        }

        .mk-row label span{
            color: red;
        }

        .mk-submit{
            text-align: center;
        }
    </style>
    <article class="cl pd-20">
        <div class="mt-20 mk-hasbtn">
            <div class="mk-row">
                <label><span>*</span>点播服务器名:</label>
                <input type="text" class="input-text radius size-M" name="vodsvrname">
            </div>
            <div class="mk-row">
                <label><span>*</span>ip地址:</label>
                <input type="text" class="input-text radius size-M" name="ip">
            </div>
            <div class="mk-row">
                <label><span>*</span>端口:</label>
                <input type="text" class="input-text radius size-M" name="port">
            </div>
            <div class="mk-row">
                <label><span>*</span>点播服务器对应的载体id:</label>
                <input type="text" class="input-text radius size-M" name="vodsvrstoragerid">
            </div>
            <div class="mk-row">
                <label><span>*</span>点播服务器存储路径:</label>
                <input type="text" class="input-text radius size-M" name="vodsvrpath">
            </div>

            <div class="mk-submit">
                <button id="mkJsSubmit" class="btn btn-primary radius">提交</button>
            </div>
        </div>
    </article>
    <include file="./Application/Home/View/Public/Base/_footer.html"/>
    <script>
        $("#mkJsSubmit").click(function(){
            var regNum = new RegExp("^[0-9]*$");
            var regIp = /^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$/
            var vodsvrname = $("input[name='vodsvrname']").val();
            var ip = $("input[name='ip']").val();
            var port = $("input[name='port']").val();
            var vodsvrstoragerid = $("input[name='vodsvrstoragerid']").val();
            var vodsvrpath = $("input[name='vodsvrpath']").val();
            if(!vodsvrname){
                layer.msg('点播服务器名不能为空', {
                    icon: 2,
                    time: 1000
                });
                return;
            }else if(!ip){
                layer.msg('ip地址不能为空', {
                    icon: 2,
                    time: 1000
                });
                return;
            }else if(!port){
                layer.msg('端口不能为空', {
                    icon: 2,
                    time: 1000
                });
                return;
            }else if(!vodsvrstoragerid){
                layer.msg('点播服务器对应的载体id不能为空', {
                    icon: 2,
                    time: 1000
                });
                return;
            }else if(!vodsvrpath){
                layer.msg('点播服务器存储路径不能为空', {
                    icon: 2,
                    time: 1000
                });
                return;
            }

            if(!regIp.test(ip)){
                layer.msg('只能输入合法的IP地址', {
                    icon: 2,
                    time: 1000
                });
                return;
            }

            if(!regNum.test(port)){
                layer.msg('端口只能输入数字', {
                    icon: 2,
                    time: 1000
                });
                return;
            }
            var url = "{:U('Home/index/addVodSvr1')}";
            var data = {
                vodsvrname:vodsvrname,
                ip:ip,
                port:port,
                vodsvrstoragerid:vodsvrstoragerid,
                vodsvrpath:vodsvrpath
            }
            $.post(url,data,function(res){
//                    console.log(res);
                if(res === 0){
                    layer.msg('添加成功', {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.location.reload();
                    },1000);
                }else {
                    layer.msg('添加失败，请重试', {
                        icon: 2,
                        time: 1000
                    });
                }
            })
        })
    </script>
</block>